package com.itheima.logdemo.user;

import com.itheima.logdemo.utils.LogInfo;
import com.itheima.logdemo.utils.LogUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

@RestController
public class UserController {

    private Map<Integer,String> db = new HashMap(){{
        put(1,"zhangsan");
        put(2,"lisi");
        put(3,"wangwu");
        put(4,"xiaoming");
        put(5,"laoli");
    }};

    /**
     * user微服务方法，提供给api模块调用
     */
    @LogInfo
    @GetMapping("/info")
    public String info(@RequestParam Integer id) throws InterruptedException {

        LogUtil.log("I am user.UserController");
        LogUtil.log("current user is "+db.get(id));

        Thread.sleep(new Random().nextInt(1000));

        return db.get(id);
    }

}
